package model

import (
	"time"

	"gddgame.cc/galaxy/common/dsl/game/task"
	"gddgame.cc/galaxy/utils"
)

const ZoneNodeName = "zone_node"

type ZoneNode struct {
	Key          string            `json:"key" orm:"primary" sql:"VARCHAR"`
	Name         map[string]string `json:"name" sql:"JSON"`
	Status       bool              `json:"status" sql:"TINYINT"`
	Desc         map[string]string `json:"desc" sql:"JSON"`
	Relation     []string          `json:"relation" sql:"JSON"`
	MainTask     int               `json:"main_task" sql:"INT"`
	AdditionTask int               `json:"addition_task" sql:"INT"`
	Score        int               `json:"score" sql:"INT"`
	Percent      int               `json:"percent" sql:"INT"`
	Power        int               `json:"power" sql:"INT"`
	Mode         GameMode          `json:"mode" sql:"TINYINT"`
	UpdateTime   *time.Time        `json:"update_time" orm:"updateTime" sql:"DATETIME"`

	Level int `json:"level"`

	MainTaskInfo     *task.GameTask `json:"-"`
	AdditionTaskInfo *task.GameTask `json:"-"`
	Targets          []int          `json:"-"`
	Objects          []int          `json:"-"`
	Boss             []int          `json:"-"`

	TargetRandom *utils.WeightRandom `json:"-"`
	BossRandom   *utils.WeightRandom `json:"-"`
	ObjectRandom *utils.WeightRandom `json:"-"`
}

// 获取感染等级
func (node *ZoneNode) Init() {
	node.Level = node.ComputeLevel()
}

func (node *ZoneNode) ComputeLevel() int {
	score := node.Score
	for key, number := range NodeLevelNumber {
		if number > score {
			return key
		}
	}
	return 0
}
